<html>
<head><meta charset="utf-8"><title>static access vs reborrow · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html">static access vs reborrow</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="182060516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182060516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182060516">(Nov 27 2019 at 21:34)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="116118">@Matthew Jasper</span>. Continuing from <a href="https://github.com/rust-lang/rust/pull/66654#issuecomment-559253377" target="_blank" title="https://github.com/rust-lang/rust/pull/66654#issuecomment-559253377">this comment</a>, don't I want to check the <code>LocalInfo</code> for the local in <code>&amp;*_2</code> to see if it is a pointer to a static?</p>



<a name="182060569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182060569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182060569">(Nov 27 2019 at 21:35)</a>:</h4>
<p>There's no <code>Constant</code> involved in <code>Rvalue::Ref</code> to call <code>check_static_ptr</code> on</p>



<a name="182060572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182060572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182060572">(Nov 27 2019 at 21:35)</a>:</h4>
<p>Please don't do that except to change diagnostic messages (yes, there are cases where I have done that, but please don't add more).</p>



<a name="182060696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182060696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182060696">(Nov 27 2019 at 21:37)</a>:</h4>
<p>Is there a reason that this is different to</p>
<div class="codehilite"><pre><span></span><span class="k">const</span><span class="w"> </span><span class="n">X</span>: <span class="p">()</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">3</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="o">*</span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="p">};</span><span class="w"></span>
</pre></div>



<a name="182060773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182060773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182060773">(Nov 27 2019 at 21:38)</a>:</h4>
<p>Well I understand that it's a hack, but is there an alternative? I suppose we could try to justify not const-checking references to a <code>static</code> at all.  It's good that the <code>static mut</code> case is still getting const-checked, but I'm not actually sure why <span aria-label="smile" class="emoji emoji-263a" role="img" title="smile">:smile:</span>.</p>



<a name="182060994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182060994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182060994">(Nov 27 2019 at 21:41)</a>:</h4>
<p>If <code>3</code> was instead <code>Cell::new(3)</code> it would be different.</p>



<a name="182061065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061065">(Nov 27 2019 at 21:42)</a>:</h4>
<p>I guess that you could move the <code>is_mutating_use</code> check up in <code>visit_projection_elem</code> in <code>validation.rs</code></p>



<a name="182061093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061093">(Nov 27 2019 at 21:43)</a>:</h4>
<p>It results in extras errors in quite a few tests though.</p>



<a name="182061412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061412">(Nov 27 2019 at 21:48)</a>:</h4>
<p>Is there a reason that the type of the pointer to an AllocId for a <code>static</code> is a reference and not a raw pointer?</p>



<a name="182061460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061460">(Nov 27 2019 at 21:49)</a>:</h4>
<p>That's the reason we still const-check static muts. Accesses to them go through a <code>*mut</code>.</p>



<a name="182061572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061572">(Nov 27 2019 at 21:50)</a>:</h4>
<p>It's a reference so that it can be safety checked correctly.</p>



<a name="182061587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061587">(Nov 27 2019 at 21:51)</a>:</h4>
<p>(without special casing)</p>



<a name="182061592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061592">(Nov 27 2019 at 21:51)</a>:</h4>
<p>I guess because access to a <code>static mut</code> must always be in unsafe, and we do unsafety checking on the MIR</p>



<a name="182061810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061810">(Nov 27 2019 at 21:54)</a>:</h4>
<p>I think we need to replicate the code you added that checks for <code>LocalInfo::StaticRef</code> in <code>visit_projection_elem</code> in <code>visit_rvalue</code> since we discard the <code>Deref</code> projection for things that look like reborrows.</p>



<a name="182061825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061825">(Nov 27 2019 at 21:54)</a>:</h4>
<p>To avoid changing behavior</p>



<a name="182061838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061838">(Nov 27 2019 at 21:54)</a>:</h4>
<p>OK</p>



<a name="182061854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061854">(Nov 27 2019 at 21:55)</a>:</h4>
<p>Once again, I understand you want this to go away in the long term, but not having it changes behavior now that we don't rely on <code>HasInteriorMut</code>.</p>



<a name="182061919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/static%20access%20vs%20reborrow/near/182061919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/static.20access.20vs.20reborrow.html#182061919">(Nov 27 2019 at 21:56)</a>:</h4>
<p>I'll have a talk with <span class="user-group-mention" data-user-group-id="1916">@WG-const-eval</span> about whether we need to const-check accesses to <code>static</code>s at all, in which case we may be able to remove it.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>